﻿package Cain.mc_cesh
{
	import flash.display.DisplayObject;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.display.BitmapData;
	/**
	 * 拍照 可傳入要拍的物件 和 區域(也是物件)
	 * @author cain@ 2009
	 */
	public class  Cesher_fn
	{
		private var mc:DisplayObject;
		private var fn:DisplayObject;
		private var ca:Cesher;
		/**
		 * 拍照
		 * @param	_mc 要拍的物件
		 * @param	_fn 拍照範圍,以此物件為範圍
		 */
		public function Cesher_fn(_mc:DisplayObject,_fn:DisplayObject ) 
		{
			mc = _mc;
			fn = _fn;
			init();
		}
		
		private function init():void
		{
			var mc_r:Rectangle = new Rectangle(mc.getRect(mc).x, mc.getRect(mc).y, mc.width, mc.height);
			var fn_r:Rectangle = new Rectangle(fn.getRect(fn).x,fn.getRect(fn).y,fn.width,fn.height);
			var mc_po:Point = new Point(mc_r.x, mc_r.y);
			var fn_po:Point = new Point(fn_r.x, fn_r.y);
			mc_po = mc.localToGlobal(mc_po);
			fn_po = fn.localToGlobal(fn_po);
			var rec = new Rectangle(fn_po.x-mc_po.x, fn_po.y-mc_po.y , fn.width, fn.height);
			ca = new Cesher(mc, rec);
		}
		/**
		 * 暫時顯示出來(trace用)
		 */
		public function shoit():void 
		{
			ca.shoit();
		}
		/**
		 * 回傳拍好的BitmapDat
		 * @return 回傳拍好的BitmapDat
		 */
		public function bitmapData():BitmapData
		{
			var bit2:BitmapData;
			bit2 = ca.bitmapData();
			return bit2;
		}
	}
	
}